/**************************************************************************************
*
*	Copyright (C) 2010 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	TextureSample.h
*
*	Description -	This class stores texture settings together with the actual texture.
*
*	Comments	-	Texture settings - filtering ops
*
*	Modification History:
*			Name			   Date					Description
*			CodeSushi	-	12/29/2010	-	Creation of this file
**************************************************************************************/

#ifndef _PSX_TEXTURE_SAMPLER_H_
#define _PSX_TEXTURE_SAMPLER_H_

#include "PulseSTD.h"
#include "GraphicsTypes.h"

namespace Pulse
{

	class TextureSampler
	{
	public:

		TextureSampler( void );
		~TextureSampler( void );

		void SetTextureUnit( UINT unit ) const;

		UINT GetTextureUnit( void ) const;

		void Bind( void );
		void Unbind( void );

		Texture * GetTexture( void ) const;

		const CHAR * GetTextureName( void );

		void SetTexture( Texture *pTexture );

		void SetTexture( const CHAR *pName );

		void SetAddressingMode( ETextureAddressingMode::Type mode );

		void SetMinFilter( ETextureFilter::Type filter );

		void SetMagFilter( ETextureFilter::Type filter );

		void SetMipFilter( ETextureFilter::Type filter );

		BOOL IsForceSet( void ) const;

		void SetEnabled( BOOL bEnable );

		BOOL IsEnabled( void ) const;

		void SetClearFlags( DWORD flags );

		void SetClearFlag( EClearBufferType::Type flag );

		BOOL HasClearFlag( EClearBufferType::Type flag );

		void ClearClearFlag( EClearBufferType::Type flag );

		DWORD GetClearFlags( void ) const;

	private:

		Texture *m_pTexture;
		String m_textureName; // Name of the texture being used
		
		UINT m_textureUnit;	// Texture unit the sampler is assigned to

		// Texture filtering options
		ETextureFilter::Type m_filterMin;
		ETextureFilter::Type m_filterMag;
		ETextureFilter::Type m_filterMip;

		// Texture addressing mode
		ETextureAddressingMode::Type m_addressMode;

		DWORD m_clearFlags;

		BOOL m_bForceSet;
		BOOL m_bEnabled;

	};

	//PSX_INLINE void TextureSampler::SetTextureUnit( UINT unit )
	//{
	//	m_textureUnit = unit;
	//}

	PSX_INLINE UINT TextureSampler::GetTextureUnit( void ) const
	{
		return m_textureUnit;
	}

	PSX_INLINE Texture * TextureSampler::GetTexture( void ) const
	{
		return m_pTexture;
	}

	PSX_INLINE const CHAR * TextureSampler::GetTextureName( void )
	{
		return m_textureName.GetCString();
	}

	PSX_INLINE void TextureSampler::SetTexture( Texture *pTexture ) 
	{
		m_pTexture = pTexture;
	}

	PSX_INLINE void TextureSampler::SetAddressingMode( ETextureAddressingMode::Type mode )
	{
		m_addressMode = mode;
	}

	PSX_INLINE void TextureSampler::SetMinFilter( ETextureFilter::Type filter )
	{
		m_filterMin = filter;
	}

	PSX_INLINE void TextureSampler::SetMagFilter( ETextureFilter::Type filter )
	{
		m_filterMag = filter;
	}

	PSX_INLINE void TextureSampler::SetMipFilter( ETextureFilter::Type filter )
	{
		m_filterMip = filter;
	}

	PSX_INLINE BOOL TextureSampler::IsForceSet( void ) const
	{
		return m_bForceSet;
	}

	PSX_INLINE void TextureSampler::SetEnabled( BOOL bEnable )
	{
		m_bEnabled = bEnable;
	}

	PSX_INLINE BOOL TextureSampler::IsEnabled( void ) const
	{
		return m_bEnabled;
	}

	PSX_INLINE void TextureSampler::SetClearFlags( DWORD flags )
	{
		m_clearFlags = flags;
	}

	PSX_INLINE DWORD TextureSampler::GetClearFlags( void ) const
	{
		return m_clearFlags;
	}

	PSX_INLINE BOOL TextureSampler::HasClearFlag( EClearBufferType::Type flag )
	{
		return (m_clearFlags & flag) ? TRUE : FALSE;
	}

	PSX_INLINE void TextureSampler::ClearClearFlag( EClearBufferType::Type flag )
	{
		m_clearFlags &= ~EClearBufferType::DEPTH;
	}

	PSX_INLINE void TextureSampler::SetClearFlag( EClearBufferType::Type flag )
	{
		m_clearFlags |= flag;
	}

}

#endif /* _PSX_TEXTURE_SAMPLER_H_ */